package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "C端-订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户提交订单
     *
     * @param dto 用户的请求参数dto
     * @return R
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrdersSubmitDTO dto) {
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(dto);
        return Result.success(orderSubmitVO);
    }

    /**
     * 历史订单查询
     *
     * @param dto dto
     * @return R
     */
    @GetMapping("/historyOrders")
    public Result<PageBean> queryingHistoryOrders(OrdersPageQueryDTO dto) {
        PageBean pageBean = orderService.queryingHistoryOrders(dto);
        return Result.success(pageBean);
    }

    /**
     * 查询订单详情
     *
     * @param id 订单id
     * @return R
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> selectWithDetailById(@PathVariable Long id) {
        OrderVO orderVO = orderService.selectWithDetailById(id);
        return Result.success(orderVO);
    }

    /**
     * 再来一单
     *
     * @param id 订单id
     * @return R
     */
    @PostMapping("/repetition/{id}")
    public Result<String> oneMoreOrder(@PathVariable Long id) {
        orderService.oneMoreOrder(id);
        return Result.success();
    }

    /**
     * 取消订单
     *
     * @param id 订单id
     * @return R
     */
    @PutMapping("/cancel/{id}")
    public Result<String> cancelOrder(@PathVariable Long id) {
        orderService.cancelOrder(id);
        return Result.success();
    }

    /**
     * 订单支付
     *
     * @param dto dto
     * @return R
     */
    @PutMapping("/payment")
    public Result<String > payment(@RequestBody OrdersPaymentDTO dto) {
       String time = orderService.payment(dto);
       return Result.success(time);
    }


    /**
     * 用户催单
     * @param id 订单id
     * @return R
     */

    @GetMapping("/reminder/{id}")
    public Result<String> reminderOrder(@PathVariable Long id){
        orderService.reminderOrder(id);
        return Result.success();
    }


//    public Result<String> paySuccess(){
//
//    }
}